package com.xu.common.qiNiu;

import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 七牛云配置类
 *
 * @author xu
 * 2022/7/22 11:11
 */
@Configuration
@RequiredArgsConstructor
public class QiNiuConfig {
    private final QiNiuProperty qiNiuProperty;

    /**
     * 云空间的用户信息
     */
    @Bean
    public Auth auth() {
        return Auth.create(qiNiuProperty.getAccessKey(), qiNiuProperty.getSecretKey());
    }

    /**
     * 上传的控制器
     */
    @Bean
    public UploadManager uploadManager() {
        return new UploadManager(configuration());
    }

    /**
     * 设置地区 减少带宽
     */
    @Bean
    public com.qiniu.storage.Configuration configuration(){
        return new com.qiniu.storage.Configuration(Region.huanan());
    }

    /**
     * 当前的存储空间
     */
    @Bean
    public BucketManager bucketManager(){
        return new BucketManager(auth(),configuration());
    }
}
